Link to this headingElliptic Curve Diffie Hellman (ECDH)
- ECDH Is almost the exact same as regular Diffie-Hellman. But instead of G^a its G*a.
- Works on the principle that it is hard to find G*a*b when only knowing G*a and G*b
Link to this headingImplementation
#### Setup
#User1 Generates their Private Public KeyPair
, =
#User2 Generates their Private Public KeyPair
, =
#### Exchange Data
# User1 recives User2's Public Key
# User2 recives User1's Public Key
#### Key Generation
#User1 Takes their Private Key and Multiplies it by User2's Public Key
= *
#User2 Takes their Private Keu and multiplies it by User1's Public Key
= *
#### Assurange that the shared key is the same
#print(user2_shared_key, user1_shared_key)
assert ==
Link to this headingProtocol Example
- User1 and User2 use the same Curve parameters:
- Lets use
y^2 = x^3 + -3 * x + b
- Lets use
- For Example let TODO
- User1 chooses a secret integer a (e.g. a = 4) and computes
G*a - User2 chooses a secret integer a (e.g. a = 3) and computes
G*b - Each User exchanges the output to each other
- User1 Computes the shared secret using
(G*b)*a - User2 Computes the shared secret using
(G*a)*b
Link to this headingAttacks
Link to this headingPollard Rho
"""
To calculate X_(i+1) = f(X_i)
:parameters:
X_i : sage.schemes.elliptic_curves.ell_point.EllipticCurvePoint_finite_field
X_i = (a_i * P) + (b_i * Q)
P : sage.schemes.elliptic_curves.ell_point.EllipticCurvePoint_finite_field
Base point on which ECDLP is defined
Q : sage.schemes.elliptic_curves.ell_point.EllipticCurvePoint_finite_field
Q = x*P, where `x` is the secret key
E : sage.schemes.elliptic_curves.ell_finite_field.EllipticCurve_finite_field_with_category
Elliptic Curve defined as y^2 = x^3 + a*x + b mod p
"""
=
# Partition S_1
return
# Partition S_2
return
# Partition S_3
return
return -1
"""
Calculate a_(i+1) = g(a)
:parameters:
a : int/long
Equivalent to a_i in X_i = a_i*P + b_i*Q
P : sage.schemes.elliptic_curves.ell_point.EllipticCurvePoint_finite_field
Base point on which ECDLP is defined
X_i : sage.schemes.elliptic_curves.ell_point.EllipticCurvePoint_finite_field
X_i = a_i*P + b_i*Q
E : sage.schemes.elliptic_curves.ell_finite_field.EllipticCurve_finite_field_with_category
Elliptic Curve defined as y^2 = x^3 + a*x + b mod p
"""
=
# Partition S_1
return
# Partition S_2
return 2* %
# Partition S_3
return %
return None
"""
Calculate a_(i+1) = g(a)
:parameters:
a : int/long
Equivalent to a_i in X_i = a_i*P + b_i*Q
P : sage.schemes.elliptic_curves.ell_point.EllipticCurvePoint_finite_field
Base point on which ECDLP is defined
X_i : sage.schemes.elliptic_curves.ell_point.EllipticCurvePoint_finite_field
X_i = a_i*P + b_i*Q
E : sage.schemes.elliptic_curves.ell_finite_field.EllipticCurve_finite_field_with_category
Elliptic Curve defined as y^2 = x^3 + a*x + b mod p
"""
=
# Partition S_1
return %
# Partition S_2
return 2* %
# Partition S_3
return
return None
=
=
=
=
=
=
=
=
= 1
# Single Step Calculations
=
=
=
# Double Step Calculations
=
=
=
break
assert == 1
return %
+= 1
continue
"""
Anomalous = ShortWeierstrassCurve(
name="Anomalous",
a=1456400922,
b=2005615003,
prime_mod=(pow(2,31) - 1),
order=(pow(2,31) - 1),
#2^5 * 3^7 * 17 * 19
)
x = secure_rand_between(0, Anomalous.order)
ys = Anomalous.find_points_by_x(x)
Anomalous_Generator_Point = Point(x, ys[0], Anomalous)
print(Anomalous_Generator_Point)
"""
=
=
=
=
=
=
=
=
=
=
=
=
=
=
#### Setup
#User1 Generates their Private Public KeyPair
, =
#User2 Generates their Private Public KeyPair
, =
#### Exchange Data
# User1 receives User2's Public Key
# User2 receives User1's Public Key
#### Key Generation
#User1 Takes their Private Key and Multiplies it by User2's Public Key
= *
#User2 Takes their Private Keu and multiplies it by User1's Public Key
= *
#### Assurance that the shared key is the same
#print(user2_shared_key, user1_shared_key)
assert ==
=
#3735087922 TinyCurve32: x=612544702, y=2755544091
#50009172 TinyCurve32: x=2971908904, y=1911617225
#3735087922
#[Finished in 4.1s]
Link to this headingInvalid Curve Point attack
- Not testing that both points
xandyare on the curve can break the protocol
Link to this headingOptimus Anti-Primes
Since multiplication is commutative, it’s possible that two unrelated pairs of participants could perform an ECDH step and agree on the same shared secret.
This is true for the same reason that 3\times{8} = 4\times{6}, and because your secret key is a random integer.
For this reason, it’s generally unwise to use raw ECDH outputs as encryption keys. Instead, you want to use a cryptographic hash function over the ECDH output and each participants’ public keys to guarantee your symmetric session key is distinct from other pairs.